<script setup lang='ts'>
  import { onMounted, reactive } from 'vue';
  import { statisticsApi } from '@/api/controller';
  import { Toastloading } from '@/utils/public';
  import { getPlayEndTime, getDateArray } from '@/utils'
  import Pagination from "@/components/Pagination/index.vue";
  const action = reactive({
    total:0,
    list:[] as any[],
    dateArr:getDateArray('canon') as Array<number>
  })
  const listQuery = reactive({
    page: 1,
    limit: 20,
  })
  const handleFilter = ()=>{
    listQuery.page = 1
    getList()
  }
  const resetQuery = ()=>{
    Object.assign(listQuery,{
      page:1,
      limit:20,
    })
    action.dateArr = getDateArray('canon') as Array<number>
    getList()
  }
  const getList = async()=> {
    const loading = Toastloading()
    const timeObi = getPlayEndTime(action.dateArr)
    const res = await statisticsApi.gameDayStatistics({
      ...listQuery,
      created_st:timeObi.playTime,
      created_ed:timeObi.endTime
    })
    loading.close()
    const { data=[], total=0 } = res.data
    action.list = data
    action.total = total
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">日期：</div>
          <el-date-picker
            v-model="action.dateArr"
            type="daterange"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          />
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="handleFilter">查询</el-button>
          <el-button type="primary" @click="resetQuery">重置</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column width="120" prop="id" label="ID" />
      <el-table-column min-width="120" prop="ymd" label="日期" />
      <el-table-column min-width="120" sortable prop="second_all" label="当日游戏总分钟数" />
      <el-table-column min-width="120" sortable prop="second_2" label="当日你说我猜总分钟数" />
      <el-table-column min-width="120" sortable prop="second_3" label="当日飞行棋中分钟数" />
      <el-table-column min-width="120" sortable prop="second_4" label="当日数字炸弹总分钟数" />
      <el-table-column min-width="120" sortable prop="room_open_num" label="当日总在线房间数量（包含小窝）" />
      <el-table-column min-width="120" sortable prop="room_game_num" label="游戏房间开启数量" />
      <el-table-column min-width="120" sortable prop="ai_num" label="当日成功添加机器人数量" />
      <el-table-column min-width="120" sortable prop="ai_game_num" label="机器人的总局数" />
      <el-table-column min-width="120" sortable prop="ai_diamond" label="机器人的总消耗钻石" />
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
  </div>
</template>